

/***
 * 
 * 
 *  * 其他写法：实现接口，继承具体实现的类
 * class Target {
 *  trans()
 * }
 * class Translator{
 *  aaa()
 *  bbb()
 * }
 * class Adapter extends Translator implements Target{
 *       trans(a){
 *            if(a==1){
 *              this.aaa()
 *          }else if(a==2){
 *              this.bbb()
 *          }
 *       }
 * }
 * 
 */
const TypeEnum={
    INSIDE:"inside",
    APP_FRONT:"appFront"
}
class InsideInterface{
    
    http(){
        throw new Error("http")
    }
}

class AppFrontInterface{
    postRequest(){
        throw new Error("postRequest")
    }
}

class RealInside extends InsideInterface{
    http(){
        console.log("我是用inside接口请求")
    }
}

class RealAppFront extends AppFrontInterface{
    postRequest(){
        console.log("我是用postRequest接口请求")
    }
}
/***
 * 
 * 中间可以增加一个适配器实现InsideInterface。此类可拥有适配器请求http
 * adapter
 */
class Request extends InsideInterface{
    constructor(type){
        super()
        this.type = type
        if(type == TypeEnum.APP_FRONT){
            this.requet = new RealAppFront()
        }else if(type === TypeEnum.INSIDE){
            this.requet = new RealInside()
        }
    }
    http(){//ts  instanceof
        if(this.type == TypeEnum.APP_FRONT){
            return this.requet.postRequest()
        }else if(this.type == TypeEnum.INSIDE){
            return this.requet.http()
        }
    }
}

const requst = new Request(TypeEnum.INSIDE)
requst.http()
